#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import base64
import random
import time
from io import BytesIO
import cv2
from PIL import Image
from selenium.webdriver import ActionChains

from common.readelement import Element
from page_object.webpage import WebPage
from tools.logger import Log
from bs4 import BeautifulSoup
import re

serchJob = Element('jzsz/personal/serchjob')


class SerchJobPage(WebPage):
    """工作搜索类"""

    def choose_fulltime_job(self):
        """选择找全职"""
        self.is_click(serchJob['找全职'])

    def choose_area(self):
        """选择区域"""
        self.is_click(serchJob['选择工业园区'])
        # self.is_click(serchJob['选择相城区'])

    def serch_success(self):
        """
        验证搜索成功
        将第一页的job数量与地址为选中区域的数量做对比。如2者相等，则表示搜索成功
        """
        element_list = self.find_element(serchJob['job列表']).find_elements_by_xpath('li')#获取job列表
        lenth = len(element_list)
        count = 0
        for i in range(len(element_list)):
            area_xpath = serchJob['area'][1].replace("1", str(i+1))
            area_text = self.driver.find_element_by_xpath(area_xpath).text
            if area_text =="工业园区":
                count += 1
        if lenth==count:
            return True
        else:
            return False

    # def get_web_element_attribute_names(web_element):
    #     """Get all attribute names of a web element"""
    #     # get element html
    #     html = web_element.get_attribute("outerHTML")
    #     # find all with regex
    #     pattern = """([a-z]+-?[a-z]+_?)='?"?"""
    #     return re.findall(pattern, html)











